import requests
import re


def main():
    first = 1
    for i in range(1, 50):
        # 头部信息
        header = {
            'User-Agent': "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0",
            'Cookie': "__jdv=76161171|baidu|-|organic|%25E4%25BA%25AC%25E4%25B8%259C|1640310793408; __jdu=16403107934071133737778; areaId=7; PCSYCityID=CN_410000_410700_410711; shshshfpa=b9726d2a-5321-7f67-2a84-d70c1dedc7be-1640310795; shshshfpb=sDrI7eemx7SEWLgbXSNWQKQ%3D%3D; __jda=122270672.16403107934071133737778.1640310793.1640310793.1640310793.1; __jdc=122270672; token=279c6794b785880d28b89a74280dec46,2,911284; __tk=qwrYrwSCrwqBqDanqwsC2uNXqwxCKUTW1DysrwVnqAV,2,911284; __jdb=122270672.8.16403107934071133737778|1.1640310793; shshshfp=e503a4f1607ad910e69949ef9b5deb55; shshshsID=27b02b43681a8443fbb086b995ffefe1_4_1640312075683; ip_cityCode=458; ipLoc-djd=7-458-464-37568; 3AB9D23F7A4B3C9B=TVNK5RGJCK3WNU5QYNTYWXT5J4UM25L3V2GDNXSBOTMR255FVRML3ZPRVCMBCCHKF4OTAMMLDYKNANDUCEJUVY725M; user-key=b306aa5c-49c5-41cf-b06a-c43c356bf5f7"
        }
        # 修改商品id
        spid = '10021174379642'

        url = 'https://club.jd.com/comment/productPageComments.action?&productId='

        finalurl = url + spid + '&score=0&sortType=5&page=' + str(i) + '&pageSize=10&isShadowSku=0&fold=1'

        data = requests.get(url=finalurl, headers=header).text

        remodel_comment = re.compile(r'\"content\":\"([^"]+)\",\"(?:creationTime|vcontent)\"')  # 匹配评论

        comment_list = remodel_comment.findall(data)

        for i in comment_list:
            print(first, ":", i)
            first += 1


main()
